#ifndef STUDENT_EXT_H
#define STUDENT_EXT_H

#include "extension.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>

// 基础结构体定义
typedef struct {
    char name[20];  // 姓名
    int age;        // 年龄
    float score;    // 分数
} Student;

/**
 * 初始化Student实例
 */
static inline void Student_init(Student* self, const char* name, int age, float score) {
    strncpy(self->name, name, sizeof(self->name) - 1);
    self->name[sizeof(self->name) - 1] = '\0';  // 确保字符串终止
    self->age = age;
    self->score = score;
}

// --------------------------
// 扩展函数声明
// --------------------------

/**
 * 打印学生信息
 */
DEFINE_EXTENSION(Student, print_info, void);

/**
 * 判断是否及格（60分以上）
 * @return 及格返回true，否则返回false
 */
DEFINE_EXTENSION(Student, is_passed, bool);

/**
 * 更新学生分数
 * @param new_score 新分数
 */
DEFINE_EXTENSION(Student, update_score, void, float new_score);

/**
 * 比较年龄是否比另一个学生大
 * @param other 另一个学生实例指针
 * @return 年龄大返回true，否则返回false
 */
DEFINE_EXTENSION(Student, is_older_than, bool, const Student* other);

// --------------------------
// 扩展函数实现
// --------------------------

DEFINE_EXTENSION(Student, print_info, void) {
    printf("[Student] 姓名：%s，年龄：%d，分数：%.1f\n",
           self->name, self->age, self->score);
}

DEFINE_EXTENSION(Student, is_passed, bool) {
    return self->score >= 60;
}

DEFINE_EXTENSION(Student, update_score, void, float new_score) {
    self->score = new_score;
    printf("[Student] %s的分数已更新为：%.1f\n", self->name, self->score);
}

DEFINE_EXTENSION(Student, is_older_than, bool, const Student* other) {
    return self->age > other->age;
}

#endif // STUDENT_EXT_H
